package com.jl.jlapp.mvp.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.EvaluateClassifyAdapter;
import com.jl.jlapp.adapter.EvaluateListAdapter;
import com.jl.jlapp.adapter.EvaluateListAdapter.OnClickGoodsPicItemListener;
import com.jl.jlapp.eneity.EvaluateTypeModel;
import com.jl.jlapp.eneity.GoodsDetailModel;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean;
import com.jl.jlapp.mvp.activity.GoodsDetailActivity;
import com.jl.jlapp.mvp.activity.PhotoViewActivity;
import com.jl.jlapp.utils.CustomGridLayoutManager;
import com.jl.jlapp.utils.CustomLanearLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class GoodsEvaluationFragment extends Fragment implements OnClickGoodsPicItemListener {
    List<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> afterOrderByEvalList;
    EvaluateClassifyAdapter classifyAdapter;
    double compositeScores = 0.0D;
    Integer discrepancyEvalNum = Integer.valueOf(0);
    @BindView(R.id.evaluation_star1)
    ImageView evaluationStar1;
    @BindView(R.id.evaluation_star2)
    ImageView evaluationStar2;
    @BindView(R.id.evaluation_star3)
    ImageView evaluationStar3;
    @BindView(R.id.evaluation_star4)
    ImageView evaluationStar4;
    @BindView(R.id.evaluation_star5)
    ImageView evaluationStar5;
    Integer goodEvalNum = Integer.valueOf(0);
    Double goodEvaluationRating = Double.valueOf(0.0D);
    GoodsDetailActivity goodsDetailActivity;
    @BindView(R.id.has_eval_rela)
    RelativeLayout hasEvalRela;
    Integer hasPicNum = Integer.valueOf(0);
    List<ImageView> imageViews;
    EvaluateListAdapter listAdapter;
    List<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> listModels;
    Integer middleEvalNum = Integer.valueOf(0);
    @BindView(R.id.no_eval)
    TextView noEval;
    @BindView(R.id.no_evaluation)
    TextView noEvaluation;
    GoodsDetailModel.ResultDataBean resultDataBeanMsg;
    @BindView(R.id.rlv_classify_recycle_view)
    RecyclerView rlvClassify;
    @BindView(R.id.rlv_evaluate_list_recycle_view)
    RecyclerView rlvEvaluateList;
    @BindView(R.id.tv_rate_percentage_num)
    TextView tvRatePercentageNum;
    @BindView(R.id.tv_score)
    TextView tvScore;
    List<EvaluateTypeModel> typeModels;
    View view;

    public void OnClickGoodsPicItem(String paramString) {
        Intent localIntent = new Intent(getActivity(), PhotoViewActivity.class);
        localIntent.putExtra("picUrl", paramString);
        startActivity(localIntent);
    }

    public void evalMsgOrderBy(List<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> paramList) {
        this.afterOrderByEvalList = new ArrayList();
        ArrayList<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> localArrayList1 = new ArrayList();
        ArrayList<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> localArrayList2 = new ArrayList();
        ArrayList<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> localArrayList3 = new ArrayList();
        ArrayList<GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean> localArrayList4 = new ArrayList();
        for (int i = 0; i < paramList.size(); i++) {
            if (((paramList.get(i)).getScore() >= 4.0D) && (((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getScore() <= 5.0D) && (((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getEvaluationPics().size() > 0)) {
                localArrayList1.add(paramList.get(i));
            }
            if ((((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getScore() >= 4.0D) && (((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getScore() <= 5.0D) && (((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getEvaluationPics().size() <= 0)) {
                localArrayList2.add(paramList.get(i));
            } else if (((GoodsDetailModel.ResultDataBean.GoodsEvaluationsBean) paramList.get(i)).getEvaluationPics().size() > 0) {
                localArrayList3.add(paramList.get(i));
            } else {
                localArrayList4.add(paramList.get(i));
            }
        }
        if (localArrayList1.size() > 0) {
            int i = 0;
            while (i < localArrayList1.size()) {
                this.afterOrderByEvalList.add(localArrayList1.get(i));
                i += 1;
            }
        }
        if (localArrayList2.size() > 0) {
            int i = 0;
            while (i < localArrayList2.size()) {
                this.afterOrderByEvalList.add(localArrayList2.get(i));
                i += 1;
            }
        }
        if (localArrayList3.size() > 0) {
            int i = 0;
            while (i < localArrayList3.size()) {
                this.afterOrderByEvalList.add(localArrayList3.get(i));
                i += 1;
            }
        }
        if (localArrayList4.size() > 0) {
            int i = 0;
            while (i < localArrayList4.size()) {
                this.afterOrderByEvalList.add(localArrayList4.get(i));
                i += 1;
            }
        }
    }

    public void onAttach(Activity paramActivity) {
        super.onAttach(paramActivity);
        this.goodsDetailActivity = ((GoodsDetailActivity) getActivity());
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        this.view = paramLayoutInflater.inflate(R.layout.fragment_goods_evaluation, null, false);
        ButterKnife.bind(this, this.view);
        this.imageViews = new ArrayList();
        this.imageViews.add(this.evaluationStar1);
        this.imageViews.add(this.evaluationStar2);
        this.imageViews.add(this.evaluationStar3);
        this.imageViews.add(this.evaluationStar4);
        this.imageViews.add(this.evaluationStar5);
        if (this.goodsDetailActivity.resultDataBeanMsg != null) {
            this.resultDataBeanMsg = this.goodsDetailActivity.resultDataBeanMsg;
            if (this.goodsDetailActivity.resultDataBeanMsg.getGoodsEvaluations().size() > 0) {
                evalMsgOrderBy(this.goodsDetailActivity.resultDataBeanMsg.getGoodsEvaluations());
                this.noEval.setVisibility(View.GONE);
                this.rlvEvaluateList.setVisibility(View.VISIBLE);
                this.goodEvalNum = this.goodsDetailActivity.goodEvalNum;
                this.middleEvalNum = this.goodsDetailActivity.middleEvalNum;
                this.discrepancyEvalNum = this.goodsDetailActivity.discrepancyEvalNum;
                this.goodEvaluationRating = this.goodsDetailActivity.goodEvaluationRating;
                this.hasPicNum = this.goodsDetailActivity.hasPicNum;
                this.compositeScores = this.goodsDetailActivity.compositeScores;
                this.tvRatePercentageNum.setText(this.goodEvaluationRating + "");
                this.tvScore.setText(this.compositeScores + "");
                int j = (int) this.compositeScores;
                int i;
                if (this.compositeScores + 0.5D >= j + 1) {
                    i = 0;
                    if (i < j + 1) {
                        if (i < j) {
                            ((ImageView) this.imageViews.get(i)).setImageResource(R.drawable.icon_star_yellow_s);
                        }
                        i += 1;
                        ((ImageView) this.imageViews.get(i)).setImageResource(R.drawable.icon_star_half_s);
                    }
                } else {
                    i = 0;
                    while (i < j) {
                        ((ImageView) this.imageViews.get(i)).setImageResource(R.drawable.icon_star_yellow_s);
                        i += 1;
                    }
                }
                setEvaluationStatisticsData();
                setEvaluationAdapter();
                setAdapter();
            }
        }
        this.hasEvalRela.setVisibility(View.GONE);
        this.noEvaluation.setVisibility(View.VISIBLE);
        this.noEval.setVisibility(View.VISIBLE);
        this.rlvEvaluateList.setVisibility(View.GONE);
        this.hasEvalRela.setVisibility(View.GONE);
        this.noEvaluation.setVisibility(View.VISIBLE);
        this.noEval.setVisibility(View.VISIBLE);
        this.rlvEvaluateList.setVisibility(View.GONE);
        return this.view;
    }

    public void setAdapter() {
        this.rlvClassify.setLayoutManager(new CustomGridLayoutManager(getActivity(), 5, false));
        this.classifyAdapter = new EvaluateClassifyAdapter(R.layout.item_classify_list, this.typeModels);
        this.classifyAdapter.setClickItemNum(0);
        this.rlvClassify.setAdapter(this.classifyAdapter);
        this.classifyAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                TextView tv_evaluate_type = paramAnonymousView.findViewById(R.id.tv_evaluate_type);
                GoodsEvaluationFragment.this.listModels.clear();
                String trim = tv_evaluate_type.getText().toString().trim();
                int n = -1;
                if (trim.equals("全部评价")) {
                    n = 0;
                }
                if (trim.equals("好评")) {
                    n = 1;
                }
                if (trim.equals("中评")) {
                    n = 2;
                }
                if (trim.equals("差评")) {
                    n = 3;
                }
                if (trim.equals("有图")) {
                    n = 4;
                }


                int i = 0;
                while (i < GoodsEvaluationFragment.this.afterOrderByEvalList.size()) {
                    GoodsEvaluationFragment.this.listModels.add(GoodsEvaluationFragment.this.afterOrderByEvalList.get(i));
                    i += 1;
                }
                if (GoodsEvaluationFragment.this.listModels.size() == 0) {
                    GoodsEvaluationFragment.this.noEval.setVisibility(View.VISIBLE);
                    GoodsEvaluationFragment.this.rlvEvaluateList.setVisibility(View.GONE);
                }
                GoodsEvaluationFragment.this.classifyAdapter.setClickItemNum(0);
                GoodsEvaluationFragment.this.classifyAdapter.notifyDataSetChanged();
                GoodsEvaluationFragment.this.noEval.setVisibility(View.GONE);
                GoodsEvaluationFragment.this.rlvEvaluateList.setVisibility(View.VISIBLE);
                GoodsEvaluationFragment.this.listAdapter.notifyDataSetChanged();
            }
        });
    }

    public void setEvaluationAdapter() {
        this.listModels = new ArrayList();
        int i = 0;
        while (i < this.afterOrderByEvalList.size()) {
            this.listModels.add(this.afterOrderByEvalList.get(i));
            i += 1;
        }
        this.noEval.setVisibility(View.GONE);
        this.rlvEvaluateList.setVisibility(View.VISIBLE);
        this.rlvEvaluateList.setLayoutManager(new CustomLanearLayoutManager(getActivity(), false));
        this.listAdapter = new EvaluateListAdapter(R.layout.item_evaluate_list, this.listModels);
        this.listAdapter.setOnClickGoodsPicItemListener(this);
        this.rlvEvaluateList.setAdapter(this.listAdapter);
    }

    public void setEvaluationStatisticsData() {
        this.typeModels = new ArrayList();
        String[] arrayOfString = new String[5];
        arrayOfString[0] = "全部评价";
        arrayOfString[1] = "好评";
        arrayOfString[2] = "中评";
        arrayOfString[3] = "差评";
        arrayOfString[4] = "有图";
        String str1 = this.goodsDetailActivity.resultDataBeanMsg.getGoodsEvaluations().size() + "";
        String str2 = this.goodEvalNum + "";
        String str3 = this.middleEvalNum + "";
        String str4 = this.discrepancyEvalNum + "";
        String str5 = this.hasPicNum + "";
        int i = 0;
        while (i < arrayOfString.length) {
            EvaluateTypeModel localEvaluateTypeModel = new EvaluateTypeModel();
            localEvaluateTypeModel.setType(arrayOfString[i]);
            localEvaluateTypeModel.setEvaluate_num(new String[]{str1, str2, str3, str4, str5}[i]);
            this.typeModels.add(localEvaluateTypeModel);
            i += 1;
        }
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/GoodsEvaluationFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */